package com.matt.controller.pad;


import com.matt.foundation.DO.ClassListDO;
import com.matt.commons.dto.sso.StaffDTO;;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.commons.model.StatusResponse;
import com.matt.service.ClassesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.matt.foundation.constant.RequestConstant.TICKET;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/6
 * *******************************
 */
@RestController
@RequestMapping("/pad/classes")
@Slf4j
public class PadClassesController {

    @Autowired
    private ClassesService classesService;

    @Autowired
    private MemVerificationCache cache;

    @RequestMapping("/my_list")
    public StatusResponse myClasses(@RequestHeader(TICKET) String ticket){
        StaffDTO baseInfo = cache.getStaff(ticket);
        List<ClassListDO> classesList= classesService.getClassesByTeacher(baseInfo.getId(), baseInfo.getAreaId());
        classesList = classesList.stream().sorted((o1, o2) -> o1.getCategory().compareTo(o2.getCategory())).collect(Collectors.toList());
        return StatusResponse.success(classesList);
    }


    @RequestMapping("/plan")
    public StatusResponse plan(@RequestHeader(TICKET) String ticket, String classesId ,String date){
        Map response = classesService.getPlanByClasses(classesId, date, ticket, cache.getStaffId(ticket));
        return StatusResponse.success(response);
    }

    @RequestMapping("/members")
    public StatusResponse members(String classesId){
        Map response = classesService.getMemberByClassesId(classesId);
        return StatusResponse.success(response);
    }
}
